package com.openvas.controller;

import java.util.List;

import com.openvas.commons.common.annotation.Log;
import com.openvas.commons.common.core.controller.BaseController;
import com.openvas.commons.common.core.domain.AjaxResult;
import com.openvas.commons.common.core.page.TableDataInfo;
//    import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.openvas.commons.common.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


import com.openvas.domain.TableFilter;
import com.openvas.service.ITableFilterService;




/**
 * 过滤器Controller
 * 
 * @author ruoyi
 * @date 2021-11-04
 */
@Controller
@RequestMapping("/api/filter")
public class TableFilterController extends BaseController
{
    private String prefix = "system/filter";

    @Autowired
    private ITableFilterService tableFilterService;

//   // //  @RequiresPermissions("system:filter:view")
    @GetMapping()
    public String filter()
    {
        return prefix + "/filter";
    }

    /**
     * 查询过滤器列表
     */
   // //  @RequiresPermissions("system:filter:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TableFilter tableFilter)
    {
        startPage();
        List<TableFilter> list = tableFilterService.selectTableFilterList(tableFilter);
        return getDataTable(list);
    }

    /**
     * 导出过滤器列表
     */
   // //  @RequiresPermissions("system:filter:export")
    @Log(title = "过滤器", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TableFilter tableFilter)
    {
        List<TableFilter> list = tableFilterService.selectTableFilterList(tableFilter);
//        ExcelUtil<TableFilter> util = new ExcelUtil<TableFilter>(TableFilter.class);
//        return util.exportExcel(list, "过滤器数据");
        return null;
    }

    /**
     * 新增过滤器
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存过滤器
     */
   // //  @RequiresPermissions("system:filter:add")
    @Log(title = "过滤器", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TableFilter tableFilter)
    {
        return toAjax(tableFilterService.insertTableFilter(tableFilter));
    }

    /**
     * 修改过滤器
     */
    @GetMapping("/edit/{filterId}")
    public String edit(@PathVariable("filterId") String filterId, ModelMap mmap)
    {
        TableFilter tableFilter = tableFilterService.selectTableFilterByFilterId(filterId);
        mmap.put("tableFilter", tableFilter);
        return prefix + "/edit";
    }

    /**
     * 修改保存过滤器
     */
   // //  @RequiresPermissions("system:filter:edit")
    @Log(title = "过滤器", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TableFilter tableFilter)
    {
        return toAjax(tableFilterService.updateTableFilter(tableFilter));
    }

    /**
     * 删除过滤器
     */
   // //  @RequiresPermissions("system:filter:remove")
    @Log(title = "过滤器", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tableFilterService.deleteTableFilterByFilterIds(ids));
    }
}
